home *** CD-ROM | disk | FTP | other *** search
- Path: lrz-muenchen.de!news
- From: watzka@stat.uni-muenchen.de (Kurt Watzka)
- Newsgroups: comp.lang.c
- Subject: Re: void ** question
- Date: 20 Mar 1996 09:24:55 GMT
- Organization: Leibniz-Rechenzentrum, Muenchen (Germany)
- Distribution: world
- Message-ID: <4ioit7$g6k@sparcserver.lrz-muenchen.de>
- References: <DoJBrL.F5t@bear.wn.bawue.de>
- NNTP-Posting-Host: sun2.lrz-muenchen.de
-
- jo@bear.wn.bawue.de (Joerg Sommrey) writes:
-
- >Hi all,
-
- >I have a question concerning conversion to `void **'. Given this piece
- >of code:
-
- >void f(void **);
- >int main(void)
- >{
- > int **ppi;
- > f(ppi);
- > return 0;
- >}
-
- >On four platforms I get three results: silence, warning and error when
- >calling f().
-
- >The FAQ states there isn't a portable way of calling a function with a
- >generic pointer by reference. This seems to be the point but I do not
- >understand why.
-
- Pointers may have different representations, depending on the type
- they point to. They need not even have the same sizes. (An exception
- are "void *" and "char *". They must have the same representation
- in C. Since every pointer can be converted to a "void *" and back
- without loss of information, a "void *" must be able to store all
- other pointer types. Yet, a pointer to a "void *" is just a type,
- there is nothing generic about it.
-
-
- >My questions:
- >1) Is `(void **) ppi' legal (which makes any tested compiler shut up)?
-
- It tells the compiler that you know what you are doing. If you
- _know_ that all pointers have the same representation on your
- machine anyway, it may be possible that you know what you are
- doing, esp. if the program is not portable anyway.
-
- >If it is legal:
- >2) Why doesn't this conversion take place silently when calling f()?
-
- Because on a lot of machines this will not work, and because the
- language is not defined that way. If your function takes a "void *"
- as it's argument, you can pass pointers to any type, including
- pointers to any pointer type to that function. So what could you
- possibly gain from a generic pointer to pointer type?
-
- Kurt
- --
- | Kurt Watzka Phone : +49-89-2180-6254
- | watzka@stat.uni-muenchen.de
- | ua302aa@sunmail.lrz-muenchen.de
-